import 'package:flutter/material.dart';

// 定义有状态组件
// 快捷键：fstfull，得安装插件：Flutter Widget Snippets
class HomePage11_2 extends StatefulWidget {
  const HomePage11_2({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage11_2> {
  // 状态变量
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('GridView组件', style: TextStyle(color: Colors.white)),
        backgroundColor: Colors.blue,
      ),

      // 2. GridView.builder 构造函数
      body: GridView.builder(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          // 侧轴方向排列3个
          crossAxisCount: 3,
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
        ),
        itemBuilder: (context, index) {
          return Container(
            color: Colors.red,
            alignment: Alignment.center,
            child: Text('Flutter程序员 $index'),
          );
        },
        // item个数
        itemCount: 30,
        // 上、下、左、右 填充10
        padding: EdgeInsets.all(10),
      ),
    );
  }
}
